package com.xiao.mall.foundation.errors;

import org.zalando.problem.AbstractThrowableProblem;
import org.zalando.problem.Status;

import java.util.HashMap;
import java.util.Map;

public class MarketResourceException extends AbstractThrowableProblem {

    private static final long serialVersionUID = 1319661515514602848L;

    private final String entityName;
    private final String errorKey;
    private final String errorValue;

    /**
     * 用户已经许愿
     * @param entityName
     * @param errorKey
     * @param errorValue
     */
    public MarketResourceException(String entityName, String message, String errorKey, String errorValue) {
        super(ErrorConstants.DEFAULT_TYPE, message, Status.BAD_REQUEST,
                null, null, null, getAlertParameters(entityName, errorKey, errorValue));
        this.entityName = entityName;
        this.errorKey = errorKey;
        this.errorValue = errorValue;
    }

    public String getEntityName() {
        return entityName;
    }

    public String getErrorKey() {
        return errorKey;
    }

    private static Map<String, Object> getAlertParameters(String entityName, String errorKey, String errorValue) {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("message", "error." + errorKey + ":" + errorValue);
        parameters.put("params", entityName);
        return parameters;
    }
}
